package com.mobimap.nhom9.gui.utls;

import java.util.ArrayList;
import java.util.List;

import com.mobimap.nhom9.dto.PlaceExDTO;
import com.mobimap.nhom9.dto.PlaceExType;
import com.mobimap.nhom9.gui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PlaceExAdapter extends BaseAdapter {
	private Context mContext;
	private List<PlaceExDTO> lstPlaces;

	public PlaceExAdapter(Context context, List<PlaceExDTO> lstPlaces) {
		this.mContext = context;
		this.lstPlaces = lstPlaces;
		if (this.lstPlaces == null) {
			this.lstPlaces = new ArrayList<PlaceExDTO>();
		}
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return lstPlaces.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.lstPlaces.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return this.lstPlaces.get(arg0).getId();
	}

	public View getView(int pos, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.activity_placeresult_item, null);
		}
		PlaceExDTO placeExDto = this.lstPlaces.get(pos);
		
		// Get widget
		ImageView icon = (ImageView) convertView
				.findViewById(R.id.placeresult_item_picture);
		TextView header = (TextView) convertView
				.findViewById(R.id.placeresult_item_header);
		TextView desc = (TextView) convertView
				.findViewById(R.id.placeresult_item_desc);

		//Set content to widget
		if (placeExDto.getPlaceExType() == PlaceExType.ADDRESS)	{
			icon.setImageResource(GuiHelper.getDichVuIconResource(0));
			header.setText(placeExDto.getNumber() + " " + placeExDto.getArea());
			desc.setText("");
		}
		else	{
			icon.setImageResource(GuiHelper.getDichVuIconResource(placeExDto.getTypeId()));
			header.setText(placeExDto.getFullName());
			desc.setText(placeExDto.getAddress());
		}
		return convertView;
	}
	
}
